package com.msite.service.security;

import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by tpeng on 2016/4/21.
 */
public class SimpleLoginSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler {

    public SimpleLoginSuccessHandler(String defaultTargetUrl, boolean isAlwaysUse){
        this.setDefaultTargetUrl(defaultTargetUrl);
        this.setAlwaysUseDefaultTargetUrl(isAlwaysUse);
    }

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        Object user = authentication.getPrincipal();
        System.out.println(user);
        super.onAuthenticationSuccess(request,response, authentication);
    }

}
